<template>
  <div>
    <strong>飞猫-承德旅游网</strong>
    <div class="header-avter">
      <el-avatar size="medium" :src="userInfo.avatar"></el-avatar>
      <el-dropdown>
        <span class="el-dropdown-link">
          {{
            userInfo.username
          }}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>
            <router-link to="/usercenter">修改密码</router-link>
          </el-dropdown-item>
          <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
          <!--          <el-dropdown-item disabled>开发中</el-dropdown-item>-->
          <!--          <el-dropdown-item divided>开发中</el-dropdown-item>-->
        </el-dropdown-menu>
      </el-dropdown>
      <el-link href="http://localhost:3000/">商城</el-link>
    </div>
  </div>
</template>

<script scoped>
export default {
  name: "Header",
  data() {
    return {
      userInfo: {
        id: "",
        username: "",
        avatar: "",
      },
    };
  },
  methods: {
    // 获取用户信息
    getUserInfo() {
      this.$axios.get("/cat/sysuser/info").then((res) => {
        this.userInfo = res.data.data.sysUser;
      });
    },

    // 注销
    logout() {
      this.$axios.get("/logout").then((res) => {
        // 清除
        console.log(res.data.data);
        localStorage.clear();
        sessionStorage.clear();
        this.$store.commit("resetState");
        this.$router.push("/login");
      });
    },
  },
  created() {
    this.getUserInfo();
  },
};
</script>

<style scoped>
.header-avter {
  float: right;
  width: 210px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

/* .el-menu-vertical-demo {
  background-color: #eeebf3;
  height: 100%;
} */
.el-link {
  color: #fff;
}
.el-dropdown-link{
  color: #fff;
}
</style>